<template>
  <div>
    <el-row :gutter="20" type="flex">
      <el-col v-show="sourceType == 1" :span="6">
        <CourseTitleSelect
          :defaultValue="listQueryIn.code"
          @e-courseTitleData="setCourseTitle"
        />
      </el-col>
      <el-col v-show="sourceType == 2" :span="6">
        <el-input
          placeholder="请输入课程标题"
          v-model="listQueryIn.title"
          clearable
        >
        </el-input>
      </el-col>
      <el-col :span="6">
        <el-button type="custom" @click="refreshList()" plain>搜索</el-button>
        <el-button type="custom" @click="handleAdd()">新增</el-button>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import Bus from "@/utils/bus.js";
export default {
  components: {
    CourseTitleSelect: () => import("@/components/courseTitleSelect"),
  },
  data() {
    return {
      listQueryIn: {
        title: "",
        code: "",
      },
    };
  },
  watch: {
    sourceType(v) {
      this.listQueryIn.code = "";
      this.listQueryIn.title = "";
    },
  },
  props: ["sourceType"],
  methods: {
    setCourseTitle(v) {
      this.listQueryIn.code = v.id || "";
    },
    refreshList() {
      Bus.$emit("refreshCourseList", this.listQueryIn);
    },
    handleAdd() {
      Bus.$emit("showDialogCourseAdd");
    },
  },
};
</script>